package org.springblade.project.controller;

import lombok.extern.slf4j.Slf4j;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.etl.service.EtlJobManager;
import org.springblade.core.tool.api.R;
import org.springblade.project.config.TestConfig;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


/**
 * 控制器
 *
 * @author qp
 */
@Slf4j
@RestController
@RequestMapping("/etl/job")
public class TestController extends BladeController {

    @Resource
    private TestConfig testConfig;

    @GetMapping("/test")
    public R<String> test(HttpServletRequest request) {
        try {
            String jobCode = request.getParameter("jobCode");
            EtlJobManager.runJob(jobCode, testConfig);
            return R.success("保存成功");
        } catch (Exception ex) {
            log.error("保存异常，" + ex.getMessage(), ex);
            return R.fail(ex.getMessage());
        }
    }

}

